<template>
  <div class="login">
    <CommonForm :form="form" :formLable="formLable"></CommonForm>
    <el-button type="primary" @click="confirm">确 定</el-button>
  </div>
</template>

<script>
import CommonForm from '../components/CommonForm'
export default {
  name: 'Login',
  components: { CommonForm },
  data() {
    return {
      form: {
        username: 'admin',
        password: '123456'
      },
      formLable: [
        {
          model: 'username',
          label: '用户名'
        },
        {
          model: 'password',
          label: '密码',
          type: 'password'
        }
      ]
    }
  },
  methods: {
    confirm() {
      this.$http.post('api/permission/getMenu', this.form).then(res => {
        if (res.data.code === 20000) {
          this.$store.commit('clearMenu')
          this.$store.commit('setMenu', res.data.data.menu)
          // console.log(res.data.data.token)
          this.$store.commit('setToken', res.data.data.token)
          this.$store.commit('addRoutes', this.$router)
          this.$router.push({ name: 'home' })
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.login {
  width: 540px;
  margin: 0 auto;
  .el-button {
    display: block;
    margin: 0 auto;
  }
}
</style>
